package com.designoutput.elements
{
	import com.designoutput.image.DashedLine;
	import com.designoutput.ui.newControls.ControlBase;
	
	import flash.display.Sprite;

	/**
	 * The super class with some drawing functionalities.
	 */
	public class Base extends ControlBase
	{		
		override protected function initialize():void {
			super.initialize();
			
			_width = 15;
			_height = 15;
		}

		// used in PusedoWindow, will not be used in this version.
//		function paintGradient(movie:MovieClip, nCol1:Number, nCol2:Number, nX:Number, nY:Number, nW:Number, nH:Number, strType:String):void
//		{
//			with (movie)
//			{
//				var colors:Array=[nCol1, nCol2];
//				var alphas:Array=[100, 100];
//				var ratios:Array=[0, 0xff];
//				var alpha:Number=strType == "vert" ? Math.PI / 2 : 0;
//				var matrix={matrixType: "box", x: nX, y: nY, w: nW, h: nH, r: alpha};
//				beginGradientFill("linear", colors, alphas, ratios, matrix);
//				moveTo(nX, nY);
//				lineTo(nX + nW, nY);
//				lineTo(nX + nW, nY + nH);
//				lineTo(nX, nY + nH);
//				lineto(nX, nY);
//				endFill();
//			}
//		}
		
		
		/**
		 * To draw the Triangle shape
		 * @param target
		 * @param nX1 - cater cornered point1.x
		 * @param nY1 - cater cornered point1.y
		 * @param nX2 - cater cornered point2.x
		 * @param nY2 - cater cornered point2.y
		 * @param fillColor -  color of the background line
		 * @param alpha - background aplha
		 * 
		 */			
		static public function drawTriangle(target:Sprite, nX1:Number, nY1:Number, nX2:Number, nY2:Number, fillColor:Number = 0xFFFFFF, bgAlpha:Number = 1):void{
			target.graphics.beginFill(fillColor, bgAlpha);
			target.graphics.moveTo(nX1+(nX2-nX1)/2, nY1);
			target.graphics.lineTo(nX2, nY2);
			target.graphics.lineTo(nX1, nY2);
			target.graphics.lineTo(nX1+(nX2-nX1)/2, nY1);
			target.graphics.endFill();
		}
		
		/**
		 * To draw reference line for Triangle shape
		 * @param target
		 * @param nX1 - cater cornered point1.x
		 * @param nY1 - cater cornered point1.y
		 * @param nX2 - cater cornered point2.x
		 * @param nY2 - cater cornered point2.x
		 * @param lineColor
		 * @param skipNum
		 * @param lineSize
		 * @param lineAlpha
		 * 
		 */		
		static public function drawFrameTriangleDotted(target:Sprite, nX1:Number, nY1:Number, nX2:Number, nY2:Number,lineColor:Number = 0, skipNum:Number = 3, lineSize:Number = 1,  lineAlpha:Number = 1):void{
			var adashline:DashedLine = new DashedLine(lineSize,lineColor,new Array(skipNum, skipNum));
			adashline.moveTo(nX1+(nX2-nX1)/2, nY1);
			adashline.lineTo(nX2, nY2);
			adashline.lineTo(nX1, nY2);
			adashline.lineTo(nX1+(nX2-nX1)/2, nY1);
			target.addChild(adashline);
		}
		
		
		
		/**
		 * 
		 * @param target
		 * @param nX1 - cater cornered point1.x
		 * @param nY1 - cater cornered point1.y
		 * @param nX2 - cater cornered point2.x
		 * @param nY2 - cater cornered point2.y
		 * @param solidLineColor -  color of the solid line
		 * @param alpha - background aplha
		 * @param solidLineSize -  size of the solid line
		 * 
		 */		
		static public function drawSolidRect(target:Sprite, nX1:Number, nY1:Number, nX2:Number, nY2:Number, solidLineColor:Number = 0, alpha:Number = 1, solidLineSize:Number = 1):void
		{
			if (nX1 > nX2)
			{
				var tmpX:Number=nX1;
				nX1=nX2;
				nX2=tmpX;
			}
			if (nY1 > nY2)
			{
				var tmpY:Number=nY1;
				nY1=nY2;
				nY2=tmpY;
			}
			
			var nMinSize:Number=Math.min(nX2 - nX1, nY2 - nY1);
			if (solidLineSize > nMinSize / 2)
				solidLineSize=Math.floor(nMinSize / 2);
			drawRect(target, nX1, nY1, nX2, nY1 + solidLineSize, solidLineColor, alpha);
			drawRect(target, nX1, nY1 + solidLineSize, nX1 + solidLineSize, nY2, solidLineColor, alpha);
			drawRect(target, nX1 + solidLineSize, nY2 - solidLineSize, nX2, nY2, solidLineColor, alpha);
			drawRect(target, nX2 - solidLineSize, nY1 + solidLineSize, nX2, nY2 - solidLineSize, solidLineColor, alpha);
		}

		/**
		 * 
		 * @param target
		 * @param nX1 - cater cornered point1.x
		 * @param nY1 - cater cornered point1.y
		 * @param nX2 - cater cornered point2.x
		 * @param nY2 - cater cornered point2.y
		 * @param fillColor - fill color of the rectangle
		 * @param bgAlpha - background alpha
		 * 
		 */		
		static public function drawRect(target:Sprite, nX1:Number, nY1:Number, nX2:Number, nY2:Number, fillColor:Number = 0xFFFFFF, bgAlpha:Number = 1):void
		{
			target.graphics.beginFill(fillColor, bgAlpha);
			target.graphics.drawRect(nX1, nY1, nX2 - nX1, nY2 - nY1);
			target.graphics.endFill();
		}
		
		
//		static public function drawRect(target:DisplayObject, nX1:Number,nY1:Number, nX2:Number, nY2:Number, clr:Number = 0xFFFFFF, alpha:Number = 1):void{
//			with(target){
//				target.graphics.beginFill(clr, alpha);
//				target.graphics.moveTo(nX1, nY1);
//				target.graphics.lineTo(nX2, nY1);
//				target.graphics.lineTo(nX2, nY2);
//				target.graphics.lineTo(nX1, nY2);
//				target.graphics.lineTo(nX1, nY1);
//				target.graphics.endFill();
//			}
//		}
//		
		/**
		 * 
		 * @param target
		 * @param nX1
		 * @param nY1
		 * @param nX2
		 * @param nY2
		 * @param lineColor
		 * @param lineAlpha
		 * @param lineSize
		 * 
		 */		 		
		static public function drawRectLine(target:Sprite, nX1:Number, nY1:Number, nX2:Number, nY2:Number, lineColor:Number = 0xFFFFFF, lineAlpha:Number = 1, lineSize:Number = 1):void
		{
			target.graphics.lineStyle(lineSize,lineColor,lineAlpha);
			target.graphics.beginFill(0, 0);
			target.graphics.drawRect(nX1, nY1, nX2 - nX1, nY2 - nY1);
			target.graphics.endFill();
		}

		static public function drawLineF(target:Sprite, nX1:Number, nY1:Number, nX2:Number, nY2:Number, clr:Number= 0, alpha:Number = 1):void
		{
			target.graphics.beginFill(clr, alpha);
			target.graphics.drawRect(nX1, nY1, nX2 - nX1, nY2 - nY1);
			target.graphics.endFill();
		}
		
		/**
		 * 
		 * To draw lines with blank, somewhat to show margins
		 * @param target
		 * @param nX1 - cater cornered point1.x
		 * @param nY1 - cater cornered point1.y
		 * @param nX2 - cater cornered point2.x
		 * @param nY2 - cater cornered point2.y
		 * @param clr - line color
		 * 
		 */		
		static public function drawFrameRect(target:Sprite, nX1:Number, nY1:Number, nX2:Number, nY2:Number, clr:Number = 0xFF0000):void
		{
			if (nX1 > nX2)
			{
				var tmpX:Number=nX1;
				nX1=nX2;
				nX2=tmpX;
			}
			if (nY1 > nY2)
			{
				var tmpY:Number=nY1;
				nY1=nY2;
				nY2=tmpY;
			}
			drawSolidRect(target, nX1, nY1, nX2 + 1, nY2 + 1, 0xffffff);
			// draw top line
			for (var i1:Number = nX2 + 1; i1 >= nX1 + 1; i1-=6)
			{
				drawLineF(target, Math.max(i1 - 3, nX1), nY1, i1, nY1 + 1, clr);
			}
			// draw left line
			for (var i2:Number = nY1 + 1 + nX1 - Math.max(i1 + 6, nX1); i2 <= nY2 + 1; i2+=6)
			{
				drawLineF(target, nX1, Math.max(i2, nY1 + 1), nX1 + 1, Math.min(Math.max(i2 + 3, nY1 + 1), nY2 + 1), clr);
			}
			// draw bottom line
			for (var i3:Number = nX1 + 1 - nY2 + Math.min(i2 - 6, nY2); i3 <= nX2 + 1; i3+=6)
			{
				drawLineF(target, Math.max(i3, nX1 + 1), nY2, Math.min(Math.max(i3 + 3, nX1 + 1), nX2 + 1), nY2 + 1, clr);
			}
			// draw right line
			for (var i4:Number = nY2 + nX2 - Math.min(i3 - 6, nX2); i4 > nY1; i4-=6)
			{
				drawLineF(target, nX2, Math.min(i4, nY2), nX2 + 1, Math.max(Math.min(i4 - 3, nY2), nY1 + 1), clr);
			}
		}
		
		

		/**
		 * To draw a RoundRect once knew the point on cater cornered.
		 * @param tareget
		 * @param nX1 - cater cornered point1.x
		 * @param nY1 - cater cornered point1.y
		 * @param nX2 - cater cornered point2.x
		 * @param nY2 - cater cornered point2.y
		 * @param cornerRadius
		 * @param color - line color
		 * @param alpha - line alpha
		 * @param nSize  - line size
		 *
		 */
		static public function drawRoundRect(tareget:Sprite, nX1:Number, nY1:Number, nX2:Number, nY2:Number, cornerRadius:Number, color:Number=0, alpha:Number=1, nSize:Number=1):void
		{
			var x:Number=Math.min(nX1, nX2);
			var y:Number=Math.min(nY1, nY2);
			var w:Number=Math.abs(nX2 - nX1);
			var h:Number=Math.abs(nY2 - nY1);
			tareget.graphics.lineStyle(nSize,color,alpha);
			tareget.graphics.beginFill(0, 0);
			tareget.graphics.drawRoundRect(x, y, w, h, cornerRadius*2);
			tareget.graphics.endFill();
			return;
			
			tareget.graphics.lineStyle(nSize, color, alpha);
			if (cornerRadius > 0)
			{
				var theta, angle, cx, cy, px, py;
				var cr:Number=Math.min(w, h) / 2;
				if (cornerRadius > cr)
					cornerRadius=cr;
				theta=Math.PI / 4;
				tareget.graphics.moveTo(x + cornerRadius, y);
				tareget.graphics.lineTo(x + w - cornerRadius, y);
				angle=-Math.PI / 2;
				cx=x + w - cornerRadius + (Math.cos(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				cy=y + cornerRadius + (Math.sin(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				px=x + w - cornerRadius + (Math.cos(angle + theta) * cornerRadius);
				py=y + cornerRadius + (Math.sin(angle + theta) * cornerRadius);
				tareget.graphics.curveTo(cx, cy, px, py);
				angle+=theta;
				cx=x + w - cornerRadius + (Math.cos(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				cy=y + cornerRadius + (Math.sin(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				px=x + w - cornerRadius + (Math.cos(angle + theta) * cornerRadius);
				py=y + cornerRadius + (Math.sin(angle + theta) * cornerRadius);
				tareget.graphics.curveTo(cx, cy, px, py);
				tareget.graphics.lineTo(x + w, y + h - cornerRadius);
				angle+=theta;
				cx=x + w - cornerRadius + (Math.cos(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				cy=y + h - cornerRadius + (Math.sin(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				px=x + w - cornerRadius + (Math.cos(angle + theta) * cornerRadius);
				py=y + h - cornerRadius + (Math.sin(angle + theta) * cornerRadius);
				tareget.graphics.curveTo(cx, cy, px, py);
				angle+=theta;
				cx=x + w - cornerRadius + (Math.cos(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				cy=y + h - cornerRadius + (Math.sin(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				px=x + w - cornerRadius + (Math.cos(angle + theta) * cornerRadius);
				py=y + h - cornerRadius + (Math.sin(angle + theta) * cornerRadius);
				tareget.graphics.curveTo(cx, cy, px, py);
				// draw bottom line
				tareget.graphics.lineTo(x + cornerRadius, y + h);
				// draw bl corner
				angle+=theta;
				cx=x + cornerRadius + (Math.cos(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				cy=y + h - cornerRadius + (Math.sin(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				px=x + cornerRadius + (Math.cos(angle + theta) * cornerRadius);
				py=y + h - cornerRadius + (Math.sin(angle + theta) * cornerRadius);
				tareget.graphics.curveTo(cx, cy, px, py);
				angle+=theta;
				cx=x + cornerRadius + (Math.cos(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				cy=y + h - cornerRadius + (Math.sin(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				px=x + cornerRadius + (Math.cos(angle + theta) * cornerRadius);
				py=y + h - cornerRadius + (Math.sin(angle + theta) * cornerRadius);
				tareget.graphics.curveTo(cx, cy, px, py);
				// draw left line
				tareget.graphics.lineTo(x, y + cornerRadius);
				// draw tl corner
				angle+=theta;
				cx=x + cornerRadius + (Math.cos(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				cy=y + cornerRadius + (Math.sin(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				px=x + cornerRadius + (Math.cos(angle + theta) * cornerRadius);
				py=y + cornerRadius + (Math.sin(angle + theta) * cornerRadius);
				tareget.graphics.curveTo(cx, cy, px, py);
				angle+=theta;
				cx=x + cornerRadius + (Math.cos(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				cy=y + cornerRadius + (Math.sin(angle + (theta / 2)) * cornerRadius / Math.cos(theta / 2));
				px=x + cornerRadius + (Math.cos(angle + theta) * cornerRadius);
				py=y + cornerRadius + (Math.sin(angle + theta) * cornerRadius);
				tareget.graphics.curveTo(cx, cy, px, py);
			}
			else
			{
				// cornerRadius was not defined or = 0. This makes it easy.
				tareget.graphics.moveTo(x, y);
				tareget.graphics.lineTo(x + w, y);
				tareget.graphics.lineTo(x + w, y + h);
				tareget.graphics.lineTo(x, y + h);
				tareget.graphics.lineTo(x, y);
			}
		}
		
		/**
		 * To fill color for a RoundRect
		 * @param tareget
		 * @param nX1  - cater cornered point1.x
		 * @param nY1  - cater cornered point1.y
		 * @param nX2  - cater cornered point2.x
		 * @param nY2  - cater cornered point2.y
		 * @param cornerRadius
		 * @param colorBg
		 * @param bgAlpha
		 * @param color
		 * @param alpha
		 * @param nSize
		 * 
		 */
		static public function fillRoundRect(tareget:Sprite, nX1:Number, nY1:Number, nX2:Number, nY2:Number, cornerRadius:Number, colorBg:Number=0xFFFFFF, bgAlpha:Number=1, color:Number=0, alpha:Number=1, nSize:Number=1):void
		{
			var x:Number=Math.min(nX1, nX2);
			var y:Number=Math.min(nY1, nY2);
			var w:Number=Math.abs(nX2 - nX1);
			var h:Number=Math.abs(nY2 - nY1);
			tareget.graphics.beginFill(colorBg, bgAlpha);
			tareget.graphics.drawRoundRect(x, y, w, h, cornerRadius*2);
			tareget.graphics.endFill();
			return;
			
			tareget.graphics.beginFill(colorBg, bgAlpha);
			var nOff:Number=nSize / 2;
			drawRoundRect(tareget, nX1 + nOff, nY1 + nOff, nX2 - nOff, nY2 - nOff, cornerRadius - nOff);
			tareget.graphics.endFill();
//			if (color != undefined)
//				drawRoundRect(tareget, nX1, nY1, nX2, nY2, cornerRadius, color, alpha, nSize);
		}

		

		/**
		 *
		 * @param tareget
		 * @param nX1 - The top-left controler point.x of the oval
		 * @param nY1 - The top-left controler point.y of the oval
		 * @param nX2 - The right-bottom controler point.x of the oval
		 * @param nY2 - The right-bottom controler point.y of the oval
		 * @param colorBg - background color of the oval
		 * @param nBgAlpha  - alpha color of the oval
		 * @param color - line color of the oval
		 * @param nAlpha - line alpha of the oval
		 * @param nSize - line size of the oval
		 *
		 */
		static public function fillOvalRect(tareget:Sprite, nX1:Number, nY1:Number, nX2:Number, nY2:Number, colorBg:Number=0xFFFFFF, nBgAlpha:Number=1, color:Number=0, nAlpha:Number=1, nSize:Number=1):void
		{
			var x:Number=Math.min(nX1, nX2);
			var y:Number=Math.min(nY1, nY2);
			var w:Number=Math.abs(nX2 - nX1);
			var h:Number=Math.abs(nY2 - nY1);
			tareget.graphics.beginFill(colorBg, nBgAlpha);
			tareget.graphics.drawEllipse(x,y,w,h);
			tareget.graphics.endFill();
			return;

			if (nBgAlpha == undefined)
				nBgAlpha=1;
			tareget.graphics.beginFill(colorBg, nBgAlpha);
			var nOff:Number=nSize / 2;
			drawOvalRect(tareget, nX1 + nOff, nY1 + nOff, nX2 - nOff, nY2 - nOff);
			tareget.graphics.endFill();
//			if (color != undefined)
//				drawOvalRect(tareget, nX1, nY1, nX2, nY2, color, nAlpha, nSize);
		}

		/**
		 *
		 * @param tareget
		 * @param x - the center point.x of the oval
		 * @param y - the center point.y of the oval
		 * @param xRadius - radius on the X scale from the center point
		 * @param yRadius - radius on the Y scale from the center point
		 * @param bgColor - the background color of the oval
		 * @param nBgAlpha - alpha of the oval background
		 * @param color - line color
		 * @param nAlpha - line alpha
		 *
		 */
		static public function fillOval(tareget:Sprite, x:Number, y:Number, xRadius:Number, yRadius:Number, bgColor:Number=0xFFFFFF, nBgAlpha:Number=1, color:Number=0, nAlpha:Number=1):void
		{
			if (isNaN(nBgAlpha))
				nBgAlpha=100;
			tareget.graphics.beginFill(bgColor, nBgAlpha);
			drawOval(tareget, x, y, xRadius, yRadius, color, nAlpha);
			tareget.graphics.endFill();
		}

		/**
		 * To draw a oval once the know the top-left point and the right-bottom point
		 *
		 * @param tareget
		 * @param nX1 - The top-left point.x of the oval
		 * @param nY1 - The top-left point.y of the oval
		 * @param nX2 - The right-bottom point.x of the oval
		 * @param nY2 - The right-bottom point.y of the oval
		 * @param color - line color
		 * @param nAlpha - line alpha
		 * @param nSize - line size
		 *
		 */
		static public function drawOvalRect(tareget:Sprite, nX1:Number, nY1:Number, nX2:Number, nY2:Number, color:Number=0, nAlpha:Number=1, nSize:Number=1):void
		{
			var x:Number=Math.min(nX1, nX2);
			var y:Number=Math.min(nY1, nY2);
			var w:Number=Math.abs(nX2 - nX1);
			var h:Number=Math.abs(nY2 - nY1);
			tareget.graphics.lineStyle(nSize,color,nAlpha);
			tareget.graphics.beginFill(0,0);
			tareget.graphics.drawEllipse(x,y,w,h);
			tareget.graphics.endFill();
			return;
			
			var rx:Number=Math.abs((nX1 - nX2) / 2);
			var ry:Number=Math.abs((nY1 - nY2) / 2);
			var nXSign:Number=nX1 < nX2 ? 1 : -1;
			var nYSign:Number=nY1 < nY2 ? 1 : -1;
			drawOval(tareget, nX1 + rx * nXSign, nY1 + ry * nYSign, rx, ry, color, nAlpha, nSize);
		}

		/**
		 * This will be used to draw margins for the card editor, mostly like when card is button.
		 * @param tareget
		 * @param px - the center controller's posX
		 * @param py - the center controller's posY
		 * @param xRad - the x scale width
		 * @param yRad - the y scale width
		 * @param lineColor
		 * @param skipNum
		 *
		 */
		static public function drawEllipse(tareget:Sprite, px:Number, py:Number, xRad:Number, yRad:Number, lineColor:Number, skipNum:Number):void
		{
			tareget.graphics.lineStyle(1, lineColor);
			for (var i:Number = 0; i < 360; i+=skipNum)
			{
				var a:Number;
				
				a = i * Math.PI / 180;
				tareget.graphics.moveTo(px + xRad * Math.cos(a), py + yRad * Math.sin(a));
				a = (i + 1) * Math.PI / 180;
				tareget.graphics.lineTo(px + xRad * Math.cos(a), py + yRad * Math.sin(a));
			}
		}

		/**
		 *
		 * To draw a oval
		 * @param tareget - target Sprite
		 * @param x	- the center controler's posX
		 * @param y - the center controler's posX
		 * @param xRadius - the Radius on X scale
		 * @param yRadius - the Radius on Y scale
		 * @param color - line color, default black
		 * @param nAlpha - alpha of line, , default 1. [with value 0 to 1]
		 * @param nSize -  line size, default 1
		 *
		 */
		static public function drawOval(tareget:Sprite, x:Number, y:Number, xRadius:Number, yRadius:Number, color:Number=0, nAlpha:Number=1, nSize:Number=1):void
		{
			tareget.graphics.lineStyle(nSize, color, nAlpha);
			var theta:Number, xrCtrl:Number, yrCtrl:Number, angle:Number, angleMid:Number, px:Number, py:Number, cx:Number, cy:Number;
			if (isNaN(yRadius))
				yRadius=xRadius;
			theta=Math.PI / 4;
			xrCtrl=xRadius / Math.cos(theta / 2);
			yrCtrl=yRadius / Math.cos(theta / 2);
			angle=0;
			tareget.graphics.moveTo(x + xRadius, y);
			for (var i:int = 0; i < 8; i++)
			{
				angle+=theta;
				angleMid=angle - (theta / 2);
				cx=x + Math.cos(angleMid) * xrCtrl;
				cy=y + Math.sin(angleMid) * yrCtrl;
				px=x + Math.cos(angle) * xRadius;
				py=y + Math.sin(angle) * yRadius;
				tareget.graphics.curveTo(cx, cy, px, py);
			}
		}

		// NOT CHECKED
		static public function drawArc(target:Sprite, x:Number, y:Number, radius:Number, arc:Number, startAngle:Number, yRadius:Number, color:int):Object
		{
			target.graphics.lineStyle(1, color, 100);
			
			if (isNaN(yRadius))
				yRadius=radius;
			var segAngle:Number, theta:Number, angle:Number, angleMid:Number, segs:Number, ax:Number, ay:Number, bx:Number, by:Number, cx:Number, cy:Number;
			if (Math.abs(arc) > 360)
				arc=360;
			segs=Math.ceil(Math.abs(arc) / 45);
			segAngle=arc / segs;
			theta=-(segAngle / 180) * Math.PI;
			angle=-(startAngle / 180) * Math.PI;
			ax=x - Math.cos(angle) * radius;
			ay=y - Math.sin(angle) * yRadius;
			if (segs > 0)
			{
				for (var i:Number=0; i < segs; i++)
				{
					angle+=theta;
					angleMid=angle - (theta / 2);
					bx=ax + Math.cos(angle) * radius;
					by=ay + Math.sin(angle) * yRadius;
					cx=ax + Math.cos(angleMid) * (radius / Math.cos(theta / 2));
					cy=ay + Math.sin(angleMid) * (yRadius / Math.cos(theta / 2));
					target.graphics.curveTo(cx, cy, bx, by);
				}
			}
			return {x: bx, y: by};
		}
		
		//NOT CHECKED
		static public function fillPolyLine(tareget:Sprite, arrPoints:Array, colorBg:Number, bgAlpha:Number=1, color:Number=0, alpha:Number=1, nSize:Number=1):void
		{
			if (arrPoints.length < 1)
				return;
			tareget.graphics.moveTo(arrPoints[0].x, arrPoints[0].y);
			tareget.graphics.beginFill(colorBg, bgAlpha);
			for (var i:int=1; i < arrPoints.length; i++)
				tareget.graphics.lineTo(arrPoints[i].x, arrPoints[i].y);
			tareget.graphics.endFill();
			
//			return;
//			if (arrPoints.length < 1)
//				return;
//			tareget.graphics.beginFill(colorBg, bgAlpha);
//			drawPolyLine(tareget, arrPoints, color, alpha, 0);
//			tareget.graphics.lineStyle();
//			tareget.graphics.moveTo(arrPoints[0].x, arrPoints[0].y);
//			tareget.graphics.endFill();
		}
		
		static public function drawPolyLine(tareget:Sprite, arrPoints:Array, color:Number=0, alpha:Number=1, nSize:Number=1):void
		{
			if (arrPoints.length < 1)
				return;
			tareget.graphics.moveTo(arrPoints[0].x, arrPoints[0].y);
			tareget.graphics.lineStyle(nSize, color, alpha);
			for (var i:int=1; i < arrPoints.length; i++)
				tareget.graphics.lineTo(arrPoints[i].x, arrPoints[i].y);
		}
		
		static public function drawPolyStar(tareget:Sprite, x1:Number, y1:Number, x2:Number, y2:Number, starPoints:Number, groinRatio:Number, lineA:Array = null, fillA:Array = null):void
		{
			var piHalf:Number=Math.PI / 2
			var ang:Number=Math.PI * 2 / starPoints;
			var w2:Number=Math.abs(x2 - x1) / 2;
			var h2:Number=Math.abs(y2 - y1) / 2;
			var rad:Number=h2;
			
			if(lineA){
				if (lineA[0])
				{
					tareget.graphics.lineStyle(lineA[3], lineA[1], lineA[2]);
				}
			}
			if(fillA){
				if (fillA[0])
				{
					tareget.graphics.beginFill(fillA[1], fillA[2]);
				}
			}
			
			if (lineA == null && fillA == null)
			{
				tareget.graphics.lineStyle(1, 0x000000);
			}
			// start at top
			tareget.graphics.moveTo(x1 + w2, y1 + 0);
			for (var i:Number=0; i < starPoints; i++)
			{
				var ptAng:Number=-piHalf + i * ang
				tareget.graphics.lineTo(x1 + w2 + (h2 * w2 / h2) * Math.cos(ptAng), y1 + h2 + rad * Math.sin(ptAng));
				var ptGroin:Number=ptAng + ang / 2;
				tareget.graphics.lineTo(x1 + w2 + groinRatio * (h2 * w2 / h2) * Math.cos(ptGroin), y1 + h2 + groinRatio * rad * Math.sin(ptGroin));
			}
			
			tareget.graphics.endFill();
		}
	}
}